# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Lars Kanis <lars@greiz-reinsdorf.de>

_realname=freetds
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.20
pkgrel=1
pkgdesc="A free implementation of Sybase's DB-Library, CT-Library and ODBC libraries (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://www.freetds.org/"
license=('spdx:LGPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=(https://www.freetds.org/files/stable/freetds-${pkgver}.tar.bz2
        0001-Don-t-use-MSYS2-file-libws2_32.patch)
sha256sums=('20ae11f3b806e4fbc0fa0b5931fb473bb5748bee9d487f6aa12885083578a5ed'
            '27e97c6bab28f00d5f6b00cb4a2f604e9c1919d08ee9fbd12b244461aff9f2d4')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-Don-t-use-MSYS2-file-libws2_32.patch
  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../freetds-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --includedir=${MINGW_PREFIX}/include/${_realname} \
    --enable-static \
    --enable-shared \
    --with-openssl \
    --enable-sspi

  make
}

package () {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
